package com.gz.im.backend.component;
import com.corundumstudio.socketio.SocketIOServer;
import com.gz.im.backend.component.handler.AgentEventHandler;
import com.gz.im.backend.component.handler.ImEventHandler;
import com.gz.im.backend.component.proxy.AgentEventProxy;
import com.gz.im.backend.component.proxy.ImEventProxy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;


/**
 * @author socket服务初始化与销毁
 */

@Component
@RequiredArgsConstructor
public class SocketIoServer  {
    private final SocketIOServer server;

    private final ImEventProxy imEventProxy;

    private final AgentEventProxy agentEventProxy;

	@PostConstruct
	public void init()  {
		server.addNamespace("/im/user").addListeners(new ImEventHandler(imEventProxy));
		server.addNamespace("/im/agent").addListeners(new AgentEventHandler(agentEventProxy));
		server.start();
	}
	@PreDestroy
	public void destroy() {
		server.stop();
	}
}

